home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5286 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.9 KB  |  67 lines

  1. Path: cymbal.aix.calpoly.edu!not-for-mail
  2. From: dstubbs@cymbal.aix.calpoly.edu (Dan Stubbs)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Limit on #bytes inside of struct?
  5. Date: 9 Feb 1996 09:02:31 -0800
  6. Organization: California Polytechnic State University, San Luis Obispo
  7. Message-ID: <4ffun7$1l4l@cymbal.aix.calpoly.edu>
  8. References: <4feg1d$d4g@cville-srv.wam.umd.edu> <4ffg6b$ivd@sparcserver.lrz-muenchen.de> <4ffohq$1gb@mordred.gatech.edu>
  9. NNTP-Posting-User: dstubbs@cymbal.aix.calpoly.edu
  10.  
  11. In article <4ffohq$1gb@mordred.gatech.edu>,
  12. James McIninch <james@amber.biology.gatech.edu> wrote:
  13. >ua302aa@lrz-muenchen.de wrote:
  14. >: jsquires@wam.umd.edu (jeffrey d squires) writes:
  15. >
  16. >: >I have the following:
  17. >
  18. >: >typedef struct {
  19. >: >        int zero;
  20. >: >        int one;
  21. >: >        int two;
  22. >: >        int three;
  23. >: >        int four;
  24. >: >        int five;
  25. >: >        int six;
  26. >: >        int seven_or_more;
  27. >: >} hist_type;
  28. >
  29. >: >hist_type histogram;
  30. >: >int num=2;
  31. >: >histogram.four = 0;  /* at this point, value of num changes from 2 to 0!!!*/
  32. >: >Is there a limit on the number of bytes allowed inside of a struct?
  33. >
  34. >: Yes, there is a limit on the number of bytes allowed in one 
  35. >: object. That limit is 32k. 
  36. >
  37. >No. There is no limit. Individual implementations of compilers or OS's may
  38. >impose a limit, but there is no limit that is integral to the C languag itself.
  39. >
  40.  
  41. Here is a specific program to test the above suggestions.
  42.  
  43. #include <stdio.h>
  44. int main () {
  45.  
  46.    typedef struct {
  47.       int the_array[50000];
  48.    } struct_type;
  49.  
  50.    int k;
  51.    struct_type the_struct;
  52.    int num = 2;
  53.  
  54.    puts ("Test Started");
  55.    for (k=0; k<50000; k++) {
  56.       the_struct.the_array[k] = 0;
  57.       if (num != 2)
  58.          printf ("   k = %d\n", k);
  59.    }
  60.    puts ("Test Complete");
  61. }
  62.  
  63. I ran this in a UNIX environment on two different architectures using
  64. both gcc and c89 compilers. The value of num was not changed in any of
  65. these cases. As others have noted, this is what you would expect.
  66.  
  67.